package com.controller;

import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import io.swagger.annotations.Api;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author HuangSuip
 */

@RequestMapping("/evn")
@Controller
@Transactional
@Api("evn")
public class EnvController {

private final ApplicationContext applicationContext;

    public EnvController(ApplicationContext environment) {
        this.applicationContext = environment;
    }


    @GetMapping
    @ResponseBody
    public List getView() throws IOException {
        Environment environment = applicationContext.getEnvironment();
        String work_id = environment.getProperty("WORK_ID");
        String javaHome = environment.getProperty("JAVA_HOME");
        System.out.println(javaHome);
        System.out.println(work_id);
        String[] profiles = environment.getActiveProfiles();
        String[] defaultProfiles = environment.getDefaultProfiles();
        Resource resource = applicationContext.getResource("classpath:static/index.html");
        URL url = resource.getURL();
        System.out.println(url);
        System.out.println(resource.getInputStream());
        return Arrays.asList(defaultProfiles);
    }
}
